<template>
	<el-dialog title="任务转办对话框" v-model="visible" :width="500" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="left">
			<div style="text-align: center;font-size: 18px;font-weight: 600;margin-bottom: 15px;">
				{{title}}
			</div>
				<el-form-item label="转办人" prop="changeUser">
					<el-select v-model="form.changeUser" style="width: 100%">
						<el-option v-for="item in userList" :key="item.accountId" :value="item.accountId" :label="item.userName"></el-option>
					</el-select>
				</el-form-item>
			<el-form-item label="备注" prop="changeRemark">
				<el-input v-model="form.changeRemark" maxlength="150" clearable type="textarea"></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false" >取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>

<script>
export default {
	components: {
	},
	emits: ['success', 'closed'],
	data() {
		return {
			visible: false,
			isSaveing: false,
			userList:[],
			//表单数据
			form: {
				supervisionId:'',
				processId:"",
				changeUser: "",
				changeRemark: ""
			},
			//验证规则
			rules: {
				changeUser: [
					{required: true, message: '转办人不能为空'}
				],
			}
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(){
			this.visible = true;
			return this
		},
		//表单提交方法
		submit(){
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res = await this.$API.supervision.supervisionProcess.setChangeUserByProcess.post(this.form);
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		async getSupervisionHandedUserForSelect(){
			let res = await this.$API.supervision.supervisionConfig.getSupervisionHandedUserForSelect.get({supervisionId:this.form.supervisionId});
			if (res.code == 200) {
				this.userList = res.data;
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		setData(data){
			this.form.supervisionId = data.supervisionId
			this.form.processId = data.processId
			this.title = data.title
			if(data.supervisionId!=undefined&&data.supervisionId!='')
			{
				this.getSupervisionHandedUserForSelect();
			}
		},
	}
}
</script>

<style>
</style>
